package com.livepan.business.controller;

import com.livepan.server.BaseController;
import com.livepan.server.error.BusinessException;
import com.livepan.server.response.CommonReturnType;
import com.livepan.server.service.TeacherService;
import com.livepan.server.service.model.TeacherModel;
import com.livepan.server.service.model.PageModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/teacher")
public class TeacherController extends BaseController {

    public static final String BUSINESS_NAME = "讲师";

    private static final Logger LOG = LoggerFactory.getLogger(TeacherController.class);

    @Autowired
    private TeacherService teacherService;

    @ResponseBody
    @RequestMapping("/list")
    public CommonReturnType teacher(PageModel pageModel) {
        LOG.info("page:" + pageModel.getPage());
        teacherService.list(pageModel);
        return CommonReturnType.create(pageModel);
    }

    @ResponseBody
    @RequestMapping("/all")
    public CommonReturnType all() {

        return CommonReturnType.create(teacherService.all());
    }

    @ResponseBody
    @RequestMapping("/save")
    public CommonReturnType saveTeacher(@RequestBody TeacherModel teacherModel) throws BusinessException {
        teacherService.save(teacherModel);
        return CommonReturnType.create(teacherModel);
    }

    @ResponseBody
    @RequestMapping("/delete/{id}")
    public CommonReturnType delete(@PathVariable String id) {
        teacherService.delete(id);
        return CommonReturnType.create(null);
    }
}
